﻿using System.Collections.Generic;
using System.Timers;

namespace WorldOfMUDra
{
    public class Clock : Ticker
    {
        int _minutes;

        private const int TimeOfSunset = 420;

        public delegate void ClockEvent();

        readonly List<ClockEvent> _sunSetEvents = new List<ClockEvent>();

        public bool AfterSunset
        {
            get { return (_minutes >= TimeOfSunset); }
        }

        public void AddSunSetEvent(ClockEvent eventToAdd)
        {
            _sunSetEvents.Add(eventToAdd);
        }

        protected override void OnTick(object source, ElapsedEventArgs e)
        {
            _minutes += 1;
            if (_minutes > 1440) _minutes = 0;
            if (_minutes != TimeOfSunset) return;
            foreach (ClockEvent cevent in _sunSetEvents)
            {
                cevent();
            }
        }
    }
}
